summaryrefslogtreecommitdiff
path: root/src/parser.l
blob: dff6507ce93eaf1fae732d26d3060fe4a2901488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%{
#include <stdint.h>
#include <bu/string.h>
#include "parser.tab.h"
%}

%option noyywrap

%x sitname
%x comment
%x dqstr tdqstr tsqstr
%%

[-{}<>=+/*,();]					{ return yytext[0]; }

game							{ return tokGame; }
function						{ return tokFunction; }
situation						{ return tokSituation; }
while							{ return tokWhile; }
for								{ return tokFor; }
each							{ return tokEach; }
in								{ return tokIn; }
if								{ return tokIf; }
then							{ return tokThen; }
else							{ return tokElse; }
command							{ return tokCommand; }
goto							{ return tokGoto; }

true							{ yylval.bValue = true; return tokBool; }
false							{ yylval.bValue = false; return tokBool; }
null							{ return tokNull; }

"<<"							{ BEGIN( sitname ); }
<sitname>[- a-zA-Z0-9]+			{ yylval.sValue = new Bu::String( yytext ); return tokSituationName; }
<sitname>">>"					{ BEGIN( INITIAL ); }
<sitname>.						REJECT;

"//"[^\n]*						{}

"/\*"							{ BEGIN( comment ); }
<comment>"\*/"					{ BEGIN( INITIAL ); }
<comment>.						{}

[a-zA-Z_][a-zA-Z0-9_]*			{ yylval.sValue = new Bu::String( yytext ); return tokIdent; }

[1-9][0-9]*						{
	yylval.iValue = strtoll( yytext, NULL, 10 );
	return tokInt;
}

([1-9][0-9]*)?\.[0-9]*			{
	yylval.dValue = strtod( yytext, NULL );
	return tokFloat;
}

\"\"\"							{ BEGIN( tdqstr ); yylval.sValue = new Bu::String(); }
<tdqstr>[^"]+					{ (*yylval.sValue) += yytext; }
<tdqstr>\"						{ (*yylval.sValue) += yytext; }
<tdqstr>\"\"\"					{ BEGIN( INITIAL ); return tokString; }

\'\'\'							{ BEGIN( tsqstr ); yylval.sValue = new Bu::String(); }
<tsqstr>[^']+					{ (*yylval.sValue) += yytext; }
<tsqstr>\'						{ (*yylval.sValue) += yytext; }
<tsqstr>\'\'\'					{ BEGIN( INITIAL ); return tokString; }

\"								{ BEGIN( dqstr ); yylval.sValue = new Bu::String(); }
<dqstr>[^"]+					{ (*yylval.sValue) += yytext; }
<dqstr>\"						{ BEGIN( INITIAL ); return tokString; }

[ \t\n\r]+						{}

%%